
LightMode = {
CreateUnit = function ()
	LightMode.CurFuncSeq = LightMode.FuncSeq.Pass1
end,
FuncSeq = {
	Pass1 = function ()
		if cWindow:MouseButtonDown(DIK.LBUTTON) then
			LightMode.Pos = GetPickXZ()
			local XY = cWindow:MouseXY()
			UILayout.Create(LightConfirm)
			LightConfirm.__SelfUI:NoCloseButton()
			LightConfirm.__SelfUI:SetPos(XY.x-LightConfirm.width,XY.y-LightConfirm.height)
			LightConfirm.Ok:SetOnClick(function ()
				LightConfirm.__SelfUI:Close()
				LightMode.FuncSeq.Create()
				LightMode.FuncSeq.End()
			end)
			LightConfirm.Cancel:SetOnClick(function ()
				LightConfirm.__SelfUI:Close()
				LightMode.FuncSeq.End()
			end)
			LightMode.CurFuncSeq = IdleFunc
		end
	end,
	Create = function ()

	end,
	End = function ()
		LightMode.CurFuncSeq = LightMode.FuncSeq.Pass1
	end
}
}

PointLightMode = {
	CreateUnit = function ()
		local PointLightMesh = cMeshModel:New()
		PointLightMesh:CreateSphere(cWindow:GetDevice(),10.0,10,10)
		g_MgrMesh:Add("PointLightMesh",PointLightMesh)
		PointLightMode.CurFuncSeq = PointLightMode.FuncSeq.Pass1
	end,
	FuncSeq = {
		Pass1 = function ()
			LightMode.FuncSeq.Create = PointLightMode.FuncSeq.Create
			PointLightMode.CurFuncSeq = PointLightMode.FuncSeq.Pass2
		end,
		Pass2 = function ()
			LightMode.CurFuncSeq()
		end,
		Create = function ()
			local PointLight = cPointLightObj:New()
			PointLight:SetShader("mesh.fx")
			PointLight:SetPos(LightMode.Pos)
			PointLight:SetLightEnable(false)
			PointLight:SetAmbient(GenRandColor())
			PointLight:SetMesh("PointLightMesh")
			local ObjName = GenObjName()
			g_MgrObj:Add(ObjName,PointLight)
			TRACE(string.format("PointLightMode - LightObj(%s) added\n",ObjName))
		end,
		End = function ()
		end
	}
}


DirLightMode = {
	CreateUnit = function ()
		local DirLightMesh = cMeshModel:New()
		DirLightMesh:CreateBox(cWindow:GetDevice(),10.0,10.0,20.0)
		g_MgrMesh:Add("DirLightMesh",DirLightMesh)
		DirLightMode.CurFuncSeq = DirLightMode.FuncSeq.Pass1
	end,
	FuncSeq = {
		Pass1 = function ()
			LightMode.FuncSeq.Create = DirLightMode.FuncSeq.Create
			DirLightMode.CurFuncSeq = DirLightMode.FuncSeq.Pass2
		end,
		Pass2 = function ()
			LightMode.CurFuncSeq()
		end,
		Create = function ()
			local DirLight = cDirLightObj:New()
			DirLight:SetShader("mesh.fx")
			DirLight:SetPos(LightMode.Pos)
			DirLight:SetLightEnable(false)
			DirLight:SetAmbient(GenRandColor())
			DirLight:SetMesh("DirLightMesh")
			local ObjName = GenObjName()
			g_MgrObj:Add(ObjName,DirLight)
			TRACE(string.format("DirLightMode - LightObj(%s) added\n",ObjName))
		end,
		End = function ()
		end
	}
}

SpotLightMode = {
	CreateUnit = function ()
		local SpotLightMesh = cMeshModel:New()
		SpotLightMesh:CreateCylinder(cWindow:GetDevice(),2.0,8.0,10.0,10,10)
		g_MgrMesh:Add("SpotLightMesh",SpotLightMesh)
		SpotLightMode.CurFuncSeq = SpotLightMode.FuncSeq.Pass1
	end,
	FuncSeq = {
		Pass1 = function ()
			LightMode.FuncSeq.Create = SpotLightMode.FuncSeq.Create
			SpotLightMode.CurFuncSeq = SpotLightMode.FuncSeq.Pass2
		end,
		Pass2 = function ()
			LightMode.CurFuncSeq()
		end,
		Create = function ()
			local SpotLight = cSpotLightObj:New()
			SpotLight:CreateDepthTexture(cWindow:GetDevice())
			SpotLight:SetShader("mesh.fx")
			SpotLight:SetPos(LightMode.Pos)
			SpotLight:SetLightEnable(false)
			SpotLight:SetAmbient(GenRandColor())
			SpotLight:SetMesh("SpotLightMesh")
			local ObjName = GenObjName()
			g_MgrObj:Add(ObjName,SpotLight)
			TRACE(string.format("SpotLightMode - LightObj(%s) added\n",ObjName))
		end,
		End = function ()
			SpotLightMode.CurFuncSeq = SpotLightMode.FuncSeq.Pass1
		end
	}
}

LightPropMode = {
	CreateUnit = function ()
		LightPropMode.CurFuncSeq = LightPropMode.FuncSeq.Pass1
	end,
	FuncSeq = {
		Pass1 = function ()
			if not SelectMode.HasObj() then return end
			local LightObj = SelectMode.PickObjs[1]:ToLightObj()
			if not LightObj then return end
			LightPropMode.LightObj = LightObj
			local XY = cWindow:MouseXY()
			UILayout.Create(LightProp)
			LightProp.__SelfUI:NoCloseButton()
			LightProp.__SelfUI:SetPos(XY.x-LightProp.__SelfUI:GetWidth(),XY.y-LightProp.__SelfUI:GetHeight())
			LightProp.Set:SetOnClick(function ()
				local LightObj = LightPropMode.LightObj
				local Dr = tonumber(LightProp.Dr:GetText())
				if not Dr then return end
				local Dg = tonumber(LightProp.Dg:GetText())
				if not Dg then return end
				local Db = tonumber(LightProp.Db:GetText())
				if not Db then return end
				local Da = tonumber(LightProp.Da:GetText())
				if not Da then return end
				LightObj:SetLightDiffuse(Dr,Dg,Db,Da)

				local Ar = tonumber(LightProp.Ar:GetText())
				if not Ar then return end
				local Ag = tonumber(LightProp.Ag:GetText())
				if not Ag then return end
				local Ab = tonumber(LightProp.Ab:GetText())
				if not Ab then return end
				local Aa = tonumber(LightProp.Aa:GetText())
				if not Aa then return end
				LightObj:SetLightAmbient(Ar,Ag,Ab,Aa)

				local Sr = tonumber(LightProp.Sr:GetText())
				if not Sr then return end
				local Sg = tonumber(LightProp.Sg:GetText())
				if not Sg then return end
				local Sb = tonumber(LightProp.Sb:GetText())
				if not Sb then return end
				local Sa = tonumber(LightProp.Sa:GetText())
				if not Sa then return end
				LightObj:SetLightSpecular(Sr,Sg,Sb,Sa)

				local Range = tonumber(LightProp.Range:GetText())
				if not Range then return end
				LightObj:SetLightRange(Range)

				local Falloff = tonumber(LightProp.Falloff:GetText())
				if not Falloff then return end
				LightObj:SetLightFalloff(Falloff)

				local Att0 = tonumber(LightProp.Att0:GetText())
				if not Att0 then return end
				local Att1 = tonumber(LightProp.Att1:GetText())
				if not Att1 then return end
				local Att2 = tonumber(LightProp.Att2:GetText())
				if not Att2 then return end
				LightObj:SetLightAttenuation(Att0,Att1,Att2)

				local Theta = tonumber(LightProp.Theta:GetText())
				if not Theta then return end
				LightObj:SetLightTheta(Theta)

				local Phi = tonumber(LightProp.Phi:GetText())
				if not Phi then return end
				LightObj:SetLightPhi(Phi)

			end)
			LightProp.Quit:SetOnClick(function ()
				LightProp.__SelfUI:Close()
			end)
			local D = LightObj:GetLightDiffuse()
			LightProp.Dr:SetText(tostring(D.x))
			LightProp.Dg:SetText(tostring(D.y))
			LightProp.Db:SetText(tostring(D.z))
			LightProp.Da:SetText(tostring(D.w))
			local A = LightObj:GetLightAmbient()
			LightProp.Ar:SetText(tostring(A.x))
			LightProp.Ag:SetText(tostring(A.y))
			LightProp.Ab:SetText(tostring(A.z))
			LightProp.Aa:SetText(tostring(A.w))
			local S = LightObj:GetLightSpecular()
			LightProp.Sr:SetText(tostring(S.x))
			LightProp.Sg:SetText(tostring(S.y))
			LightProp.Sb:SetText(tostring(S.z))
			LightProp.Sa:SetText(tostring(S.w))
			local Range = LightObj:GetLightRange()
			LightProp.Range:SetText(tostring(Range))
			local Falloff = LightObj:GetLightFalloff()
			LightProp.Falloff:SetText(tostring(Falloff))
			local Atten = LightObj:GetLightAttenuation()
			LightProp.Att0:SetText(tostring(Atten.x))
			LightProp.Att1:SetText(tostring(Atten.y))
			LightProp.Att2:SetText(tostring(Atten.z))
			local Theta = LightObj:GetLightTheta()
			LightProp.Theta:SetText(tostring(Theta))
			local Phi = LightObj:GetLightPhi()
			LightProp.Phi:SetText(tostring(Phi))
			LightPropMode.CurFuncSeq = IdleFunc
		end,
		End = function ()
			LightPropMode.CurFuncSeq = LightPropMode.FuncSeq.Pass1
		end
	}
}
